<template>
  <div class="biz-container">
    <table-layout :haveSider="false" :isStandTable="false">
      <template #headCustom>
        <a-steps :current="2" style="margin:10px 0" size="small">
          <a-step title="完善配送商品明细" />
          <a-step title="完善发票" />
          <a-step title="完善配送单信息" />
          <a-step title="预览并提交" />
        </a-steps>
      </template>
      <template #form>
        <div>
          <basic-form
              style="marginTop:70px"
              ref="forms"
              :isBtn="true"
              :formInfos="s_FormInfo"
              :formDatas="s_formDatas"
              :rules="s_rules"
              :buttonText="['下一步','','上一步']"
              :btnCusStyle="{ boxShadow: 'none' }"
              :isInline="true"
              @onSubmit="onNext"
              @onChangeType="onChangeType"
              @onCancel="onPrevious"
          ></basic-form>
        </div>
      </template>
    </table-layout>
    <!-- <div style="height:40px;textAlign:center;">
        <a-button type="primary" @click="onPrevious"  >上一步</a-button>
        <a-button type="primary" @click="onNext" style="marginLeft:20px" >下一步</a-button>
    </div> -->
  </div>
</template>

<script>
import searchLayout from '@/views/app/biz/common/searchLayout'
import batchOperatBtn from '@/views/app/biz/common/batchOperatBtn'
import tableLayout from '@/views/app/biz/common/index'
import aListInfo from '@/views/app/biz/common/aListInfo'
import aListTable from '@/views/app/biz/common/aListTable'
import basicForm from '../common/basicForm'
import {
  getDetailByConditions,
  getDetailByConditionsCount,
} from '../saleOrder/saleOrder'

const s_FormInfo = [ 
//   { label: '销售单号', name: 'saleOrderNo', type: 'input',isDisabled:true, placeholder: '请输入销售单号' },
  // { label: '配送单号', name: 'deliveryOrderNo', type: 'input',  placeholder: '请选择配送单号' },
  { label: '配送单名称', name: 'deliveryOrderName', type: 'input',  placeholder: '请选择配送单名称' },
  // { label: '是否关联多个订单', name: 'multipleOrder', type: 'input', placeholder: '是否关联多个订单' },
  // { label: '关联订单', name: 'associatedOrder', type: 'input', placeholder: '关联订单' },
  // { label: '物流关联单号', name: 'logisticsNo', type: 'input', placeholder: '请输入物流关联单号' },
  {},
  { label: '送货类型', name: 'deliveryType', type: 'dicselect',dicName: 'deliveryType',  placeholder: '请选择送货类型' },
  
  { label: '物流单号', name: 'logisticsNumber', type: 'input', placeholder: '请选择物流单号' },
  
  { label: '寄件地址', name: 'senderAddr', type: 'deliveryAddressSelect', placeholder: '请输入寄件人姓名' },
  {},
  { label: '寄件人姓名', name: 'sender', type: 'input', placeholder: '请输入寄件人姓名' },
  { label: '寄件人联系电话', name: 'senderTel', type: 'input', placeholder: '请输入寄件人联系电话' },
  { label: '寄件人证件类型', name: 'senderCertificateType', type: 'input', placeholder: '请输入寄件人证件类型' },
  { label: '寄件人证件号码', name: 'senderCertificateNo', type: 'input', placeholder: '请输入寄件人证件号码' },
  { label: '收件地址', name: 'receiverAddr', type: 'input', placeholder: '请输入收件地址' },
  {},
  { label: '收件人姓名', name: 'receiver', type: 'input', placeholder: '请输入收件人姓名' },
  { label: '收件人联系电话', name: 'receiverTel', type: 'input', placeholder: '请输入收件人联系电话' },
  { label: '物流方', name: 'logistics', type: 'input', placeholder: '请输入物流方' },
  { label: ['保存', '重置'], type: 'botton' },
]

const s_formDatas = {
  sysSeq: 0,
  pid: null,
  saleOrderNo: null,
  deliveryOrderNo: null,
  deliveryOrderName: null,
  multipleOrder: null,
  associatedOrder: null,
  deliveryType: null,
  logisticsNumber:null,
  sender: null,
  senderTel: null,
  senderAddr:null,
  senderCertificateType: null,
  senderCertificateNo: null,
  receiver: null,
  receiverTel: null,
  receiverAddr: null,
  logisticsNo: null,
  logistics: null,
  deliveryState:'待配送'
}
const s_rules = {
  sender: [{ required: true, message: '寄件人姓名必填', trigger: 'blur' }],
  senderTel: [{ required: true, message: '寄件人联系电话必填', trigger: 'blur' }],
  senderAddr: [{ required: true, message: '寄件地址必填', trigger: 'blur' }],
  receiver: [{ required: true, message: '收件人姓名必填', trigger: 'blur' }],
  receiverTel: [{ required: true, message: '收件人联系电话必填', trigger: 'blur' }],
  receiverAddr: [{ required: true, message: '收件地址必填', trigger: 'blur' }],
}

export default {
  components: {
    searchLayout,
    batchOperatBtn,
    tableLayout,
    aListInfo,
    aListTable,
    basicForm,
  },
  data() {
    return {
      s_FormInfo: s_FormInfo,
      s_formDatas: s_formDatas,
      s_rules: s_rules,
    }
  },
  computed: {},

  mounted(){
    
  },
  methods: {
    onNext(val){
        this.$emit('onNextStep',val)
    },
    onPrevious(){
        this.$emit('onPrevious')
    },
    setformDatas(details){
      console.log(details[0].child[0]);
      if (details[0].child[0].deliveryAddr) {
        this.s_formDatas.receiver=details[0].child[0].delivery
        this.s_formDatas.receiverTel=details[0].child[0].deliveryTel
        this.s_formDatas.receiverAddr=details[0].child[0].deliveryAddr
      }else{
        let itemIndex=this.s_FormInfo.findIndex((item)=>{
          return item.name=='receiverAddr'
        })
        let formInfo=[...this.s_FormInfo]
        formInfo[itemIndex]={ label: '收件地址', name: 'receiverAddr', type: 'deliveryAddressSelect', placeholder: '请选择收件地址' }
        this.s_FormInfo=formInfo
      }
      
    },
    // 搜索栏选择下拉select触发搜索val[0]表示选中的record中的pid,val[1]表示选中的record全部信息
    onChangeType(name, val) {
      console.log('formName',name)
      console.log('val',val)
      this.s_formDatas=this.$refs.forms.form
      switch (name) {
        case 'senderAddr': 
          if (!val[0]) {
            this.s_formDatas.senderAddr =null
            this.s_formDatas.sender =null
            this.s_formDatas.senderTel =null
          }else{
            this.s_formDatas.senderAddr =val[1].addr
            this.s_formDatas.sender =val[1].contact
            this.s_formDatas.senderTel =val[1].contactTel
          }
        break 
        case 'receiverAddr': 
          if (!val[0]) {
            this.s_formDatas.receiverAddr =null
            this.s_formDatas.receiver =null
            this.s_formDatas.receiverTel =null
          }else{
            this.s_formDatas.receiverAddr =val[1].addr
            this.s_formDatas.receiver =val[1].contact
            this.s_formDatas.receiverTel =val[1].contactTel
          }
        break
      }
    },
  },
}
</script>

<style>
</style>